﻿using DGIS.GscloudService.IService;
using DGIS.GscloudService.Service;
using DGIS.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;

namespace DGIS.Control
{
    public class GsUserControl
    {
        public Stream GetLoginValidateImg(ref CookieContainer cookieContainer,out string codekey)
        {
            IGsCloudService gsCloudService = new GsCloudService();
            Stream img = gsCloudService.GetLoginValidateImg(ref cookieContainer, out codekey);

            return img;
        }

        public bool CheackValidate(string value,string code,ref CookieContainer cookieContainer)
        {
            IGsCloudService gsCloudService = new GsCloudService();
            return gsCloudService.CheackValidate(value,code,ref cookieContainer);
        }

        /// <summary>
        /// 登录系统
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="psw"></param>
        /// <param name="key">hashkey</param>
        /// <param name="code">验证码</param>
        /// <param name="cookieContainer"></param>
        /// <returns></returns>
        public GSUser LoginWeb(string userName,string psw,string key,string code,ref CookieContainer cookieContainer,out int resultCode)
        {
            IGsCloudService gsCloudService = new GsCloudService();
            GSUser item= gsCloudService.LoginGSCloud(userName, psw,key,code, ref cookieContainer,out resultCode);            
            if(item!=null&&!string.IsNullOrEmpty(userName))
            {
                //保存到本地
                IGSUserService gsUserService = new GSUserService();
                gsUserService.AddGSUser(userName, psw);
            }

            return item;
        }

        /// <summary>
        /// 获取数据库中用户信息列表
        /// </summary>
        /// <returns></returns>
        public List<GSUser> GetDBUserList()
        {
            IGSUserService gsUserService = new GSUserService();
            return gsUserService.GetGSUserList();
        }
    }
}
